import React from 'react';
import { Input, Button, Select,  Row, Col,Card,Modal,Pagination,DatePicker} from 'antd';
import './triage.less';
import getFormatDate from '../../common/getFormatData';
import config from '../../config/config';
import $ from 'jquery';
import {browserHistory} from 'react-router';
const allRouter=config.router;
const { RangePicker } = DatePicker;
const InputGroup = Input.Group;
let allTimePhase=['00:00~00:30','00:30~01:00','01:00~01:30','01:30~02:00','02:00~02:30','02:30~03:00','03:00~03:30','03:30~04:00','04:00~04:30','04:30~05:00','05:00~05:30','05:30~06:00','06:00~06:30','06:30~07:00','07:00~07:30','07:30~08:00','08:00~08:30','08:30~09:00','09:00~09:30','09:30~10:00','10:00~10:30','10:30~11:00','11:00~11:30','11:30~12:00','12:00~12:30','12:30~13:00','13:00~13:30','13:30~14:00','14:00~14:30','14:30~15:00','15:00~15:30','15:30~16:00','16:00~16:30','16:30~17:00','17:00~17:30','17:30~18:00','18:00~18:30','18:30~19:00','19:00~19:30','19:30~20:00','20:00~20:30','20:30~21:00','21:00~21:30','21:30~22:00','22:00~22:30','22:30~23:00','23:00~23:30','23:30~24:00'];
let allTimeIndex=['00:00','00:30','01:00','01:30','02:00','02:30','03:00','03:30','04:00','04:30','05:00','05:30','06:00','06:30','07:00','07:30','08:00','08:30','09:00','09:30','10:00','10:30','11:00','11:30','12:00','12:30','13:00','13:30','14:00','14:30','15:00','15:30','16:00','16:30','17:00','17:30','18:00','18:30','19:00','19:30','20:00','20:30','21:00','21:30','22:00','22:30','23:00','23:30'];
class Triage extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            tabKey: 1,//当前显示的页面内容 1新增患者 2登记记录
            date: [], // 时间
            data1:[],//时间字符串
            Inkey: '',// 关键字
            pagesize: 12,// 每页显示的页数
            pageindex: 1,// 当前页
            allTimePhase:[],//选择医生时候模态框的时间段数组，根据门店设置的起止时间变化
            everyDoctorList:[],//选择医生时候模态框的医生筛选数组
            selectedDepartment:'',//记录是否有选择科室，筛选时为且关系
            selectedDoctor:'',//记录是否有选择医生，筛选时为且关系
            selectedTimePhase:'',//记录是否有选择时间段，筛选时为且关系
            departmentValue:'',//记录模态框已经选中的值，主要是为了取消模态框后再打开模态框select还有值  科室
            DoctorValue:'',//记录模态框已经选中的值，主要是为了取消模态框后再打开模态框select还有值   医生
            timePhaseValue:'',// 记录模态框已经选中的值，主要是为了取消模态框后再打开模态框select还有值 时间段
            DoctorScheduleList:[],//医生排班列表
            schedulingsList:[],//班次列表   总设置
            thisDoctorInfo:{},//点击模态框医生头像显示医生详情
            visible: false,//选择医生模态框
            visible1: false,//点击医生头像，确认分诊医生信息
            visible2: false,//重新预约模态框
            visible3: false,//重新预约确认模态框
            fileList:[],//上传图片列表
            age:0,//计算年龄
            patientOriginList:[],//患者来源列表
            userTypeManageList:[],//会员类型
            registrationFeeList:[],//挂号费医生展示列表
            allList:[],//所有挂号费医生列表
            allList1:[],//所有挂号费医生列表  //test
            departmentsList:[],//科室列表,模态框展示
            storeInfo:[],//门店信息
            limitNum:0,//每个医生每个时间段最多接诊多少人
            patientInfo:'',//此患者信息，在保存后，分诊需要用到
            patientInfos:{data:[]},//所有患者信息
        }
    }

    componentWillMount() {
        console.log(browserHistory);
        console.log(this.props);
        let date=getFormatDate(new Date());
        this.setState({
            data1:['','']
        });
        //获取会员类型列表
        this.getUsersList();
        this.getPatientInfo(1,'','',1);
    }
    componentDidMount() {
       this.getScheduleList();
    }
    //获取患者登记信息
    getPatientInfo(pageindex,starttime,endtime,status,value,){
        let url=allRouter.patientOrigin+'/patient/list';
        $.ajax({
            url: url,
            type: "post",
            async: true,
            traditional: true,
            headers: { Authorization: 'Bearer '+sessionStorage.getItem('token')},
            data:{
                pageindex, //页码
                pagesize:12,//每页个数
                starttime,//开始时间
                endtime,//结束时间
                status:status,//状态   1：待分诊   2：已分诊（待接诊）
                searchtext:value,//搜索关键字
            },
            success:data => {
                if(data.code===200){
                    data.data=data.data.reverse();
                    this.setState({
                        patientInfos:data,
                    },()=>{
                        console.log('患者信息 list');
                        console.log(this.state.patientInfos);
                    })
                }
            },
            error:err=>{
                console.log(err);
            }
        });
    }
    //获取会员类型列表
    getUsersList() {
        let url=allRouter.patientOrigin+'/grade/list';
        //console.log(url);
        $.ajax({
            url:url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer '+sessionStorage.getItem('token')},
            success:data=>{
                if(data.code===200){
                    this.setState({userTypeManageList:data.gread.filter(key => key.state !== '禁用')},()=>{
                        console.log(this.state.userTypeManageList);
                    })
                }else{
                    console.log("获取会员类型列表出错");
                }
            },
            error:err=>{
                console.log(err);
            }
        });
    }
     //安排分诊或者重新预约调用的函数
     handleScheduleOrAppointment(status, id) {
        //  1:待分诊  2:待接诊  3:接诊中  4.已完成
        console.log(status);
        console.log(id);
        if (status === 1 || status === 4) {
            this.setState({
                isHavingId: true,
                registedId: id,
            });
            //这是分诊
            const timeHourMinute = new Date().toTimeString().slice(0, 5);
            // console.log(timeHourMinute);
            let index = 0;
            for (let i = 0; i < allTimeIndex.length; i++) {
                if (timeHourMinute >= allTimeIndex[i] && timeHourMinute <= allTimeIndex[i + 1]) {
                    index = i;
                    break;
                }
            }
             //当前时间段 
             let myTime = allTimePhase[index];
             //获取医生排班列表
             this.getDoctorScheduleList(allTimePhase[index]);
             //获得医生信息，模态框医生筛选显示
            this.getDoctorList();
            this.setState({
                visible: true,
                selectedDepartment: '',
                selectedDoctor: '',
                selectedTimePhase: '',
                timePhaseValue: allTimePhase[index],
                departmentValue: undefined,
                doctorValue: undefined,
            });
            //获取科室列表，模态框筛选显示
            this.getDepartmentsList();
            //获得该用户的门店信息，模态框时间段筛选显示
            this.getStoreInfo(JSON.parse(sessionStorage.getItem('UserInfo')).shop[0]);
            
        } 
    }
    //改变tab页面 切换登记记录与新增患者页面内容
    changeTab(key) {
        this.setState({ tabKey: key });
        this.setState({
            date:[undefined,undefined],
            data1: ['',''],
            Inkey: undefined,
        });
        this.getPatientInfo(1,'','',key);
    }
    // 日期
    changeDate(date, str) {
        this.setState({
            date,
            data1:str,
        });
        this.getPatientInfo(1,str[0],str[1],this.state.tabKey,this.state.Inkey,);
    }
    //搜索关键字
    changeInkey(e) {
        this.setState({
            Inkey: e.target.value
        })
    }
    //搜索
    searchRoles(e) {
        let value = this.state.Inkey||'';
        console.log(value);
        this.getPatientInfo(1,this.state.data1[0],this.state.data1[1],this.state.tabKey,value);
    }
    //分页
    changePage(pageindex) {
        this.setState({
            pageindex
        });
        this.getPatientInfo(pageindex,this.state.data1[0],this.state.data1[1],this.state.tabKey,this.state.Inkey);
    }
     //获取科室列表
     getDepartmentsList() {
        let url = allRouter.patientOrigin + '/department/list';
        //console.log(url);
        $.ajax({
            url:url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer '+sessionStorage.getItem('token')},
            success:data=>{
                console.log(data);
                if (data.code === 200) {
                    //给列表每一项增加索引
                    this.setState({
                        departmentsList: data.department.filter(key => key.state !== '禁用'),
                    }, () => {
                        console.log(this.state.departmentsList);
                    })
                } else {
                    console.log("获取科室列表列表出错");
                }
            },
            error:err=>{
                console.log(err);
            }
        });
    }
    //获取总的医生排班列表
    getDoctorScheduleList(timePhase,department,doctorname) {
        console.log('timePhase');
        console.log(timePhase);
        let url = allRouter.patientOrigin + '/doctor/savePatient';
        $.ajax({
            url: url,
            type: "POST",
            async: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            data: {
                starttime: new Date().toLocaleDateString(),
                endtime: new Date().toLocaleDateString(),
                time: timePhase.slice(6, 11),
                department,
                doctorname,
            },
            success: data1 => {
                console.log("医生排班列表:");
                console.log(data1);
                if (data1.code === 200) {
                    //获取挂号费列表
                    let url = allRouter.patientOrigin + '/registration/list';
                    $.ajax({
                        url: url,
                        type: "get",
                        async: true,
                        headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                        success: data => {
                            console.log('医生挂号费列表:');
                            console.log(data);
                            if (data.code === 200) {
                                data.data=data.data.filter(key => key.state !== '禁用');
                                data1.data.map(item1=>{
                                    data.data.map(item=>{
                                        if(item1.id===item.doctorid){
                                            item1.price=item.price;
                                            item1.level=item.level;
                                        }
                                    })
                                });
                                this.setState({
                                    registrationFeeList: this.state.limitNum===0?data1.data:data1.data.filter(key=>key.totreat<this.state.limitNum),
                                },()=>{
                                    console.log(this.state.DoctorScheduleList);
                                })
                            } else {
                                console.log("获取医生挂号费列表出错");
                            }
                        },
                        error: err => {
                            console.log(err);
                        }
                    })
                } else {
                    this.setState({
                        registrationFeeList: [],
                    },()=>{
                    });
                    console.log("获取医生排班列表出错");
                }
            },
            error: err => {
                console.log(err);
            }
        })
    }
    //获取班次列表
    getScheduleList() {
        let url=allRouter.patientOrigin+'/sheduling/list';
        console.log(url);
        $.ajax({
            url:url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer '+sessionStorage.getItem('token')},
            success:data=>{
                console.log(data);
                if(data.code==200){
                    this.setState({
                        schedulingsList:data.schedulings.filter(key => key.state !== '禁用')
                    },()=>{
                        console.log('schedulingsList');
                        console.log(this.state.schedulingsList);
                    })
                }else{
                    console.log("获取班次列表出错");
                }
            },
            error:err=>{
                console.log(err);
            }
        });
    }
  //分诊选择医生模态框中选择 科室 筛选
  handleChangeDepartment(value) {
    this.setState({
        selectedDepartment: value,
        departmentValue: value,
        selectedDoctor: undefined,
        doctorValue: undefined,
    });
    this.getDoctorScheduleList(this.state.timePhaseValue,value);
    let arr=[];
    this.state.everyDoctorList1.map(item=>{
        if(item.department){
            if(item.department.length){
                if(item.department[0]._id===value){
                    arr.push(item);
                }
            }
        }
    })
    this.setState({
        everyDoctorList:arr,
    })
    
}
//分诊选择医生模态框中选择 医生 筛选
handleChangeDoctor(value) {
    this.setState({
        selectedDoctor: value,
        doctorValue: value,
    });
    this.getDoctorScheduleList(this.state.timePhaseValue,this.state.departmentValue,value)
}
//分诊选择医生模态框中选择 时间段 筛选
handleChangeTimePhase(value) {
    this.setState({
        selectedTimePhase: value,
        timePhaseValue: value,
    });
    this.getDoctorScheduleList(value,this.state.departmentValue,this.state.doctorValue)
}
    //分诊模态框点击确定，去到支付页面
    handleTriageConfirm(isHavingRegisted){
        console.log(isHavingRegisted);
        this.justSave(false,isHavingRegisted);
    }
    //获取门店信息
    getStoreInfo(storeId) {
        let url = allRouter.patientOrigin + '/cmmuseum/one/' + storeId;
        $.ajax({
            url: url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            success: data => {
                console.log(data);
                if (data.code === 200) {
                    this.setState({
                        storeInfo: data.cmmuseum,
                        limitNum: data.cmmuseum.limitnumber
                    }, () => {
                        console.log('门店信息');
                        console.log(this.state.storeInfo);
                        let startTime = this.state.storeInfo.starttime.slice(0, 5);
                        let endTime = this.state.storeInfo.endtime.slice(0, 5);
                        let startIndex = allTimeIndex.indexOf(startTime);
                        let endIndex = allTimeIndex.indexOf(endTime);
                        // console.log(startIndex);
                        // console.log(endIndex);
                        this.setState({
                            allTimePhase: (allTimePhase.slice(startIndex, endIndex))
                        }, () => {
                            console.log(this.state.allTimePhase);
                        })
                    })
                } else {
                    console.log("获取患者来源名称出错");
                }
            },
            error: err => {
                console.log(err);
            }
        });
    }
     //获取医生列表
     getDoctorList(){
        let url=allRouter.patientOrigin+'/doctor/list';
        $.ajax({
            url:url,
            type: "get",
            async: true,
            headers: { Authorization: 'Bearer '+sessionStorage.getItem('token')},
            success:data=>{
                console.log(data);
                if(data.code===200){
                    this.setState({
                        everyDoctorList:data.users.filter(key=>key.department.filter(key=>key!=null).length>0&&key.role==='医生'&&key.state!=='禁用'),
                        everyDoctorList1:data.users.filter(key=>key.department.filter(key=>key!=null).length>0&&key.role==='医生'&&key.state!=='禁用'),
                        
                    },()=>{
                        console.log('everyDoctorList');
                        console.log(this.state.everyDoctorList);
                        
                    })
                }else{
                    console.log("获取员工列表出错");
                }
            },
            error:err=>{
                console.log(err);
            }
        })
    }
    //点击医生头像，显示医生详细挂号费信息
    medicalInformation(item){
        this.setState({
            visible1: true,
        });
        console.log(item);
        this.setState({
            thisDoctorInfo:item,
        })
    }
    //只是保存登记
    justSave(mes, isHavingRegisted) {
        console.log(mes);
        console.log(isHavingRegisted);
        let thisUserInfo = [];
        if (isHavingRegisted) {
            console.log(this.state.patientInfos);
            let discount = 1;
            this.state.patientInfos.data.map(item => {
                if (item._id === this.state.registedId) {
                    thisUserInfo = item;
                    return;
                }
            });
            console.log(thisUserInfo);
            this.setState({
                shouldPayed: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price:0
            });
            let url = allRouter.patientOrigin + '/order/save';
            $.ajax({
                url: url,
                type: "post",
                async: true,
                traditional: true,
                headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                data: {
                    clinicname: this.state.storeInfo._id,//门店
                    department: this.state.thisDoctorInfo.department.id, //科室
                    doctor: this.state.thisDoctorInfo.id,//医生
                    consumptiontime: getFormatDate(new Date()) + ' ' + this.state.timePhaseValue.slice(6, 11),//  就诊时间
                    consumptionmoney: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price:0,//应收金额
                    payer: thisUserInfo._id,//付款人
                    paytype: 1,//支付类型
                    ordertype: '挂号费-' + this.state.thisDoctorInfo.department.name + this.state.thisDoctorInfo.level,//订单类型
                    chargeschedule: JSON.stringify([{
                        p_name: '挂号费',//收费名称
                        p_Number: 1,//数量
                        p_price: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,//   单价
                        p_speci: '次',// 规格
                        p_money: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,//  金额
                        p_discount: 1,// 折扣
                        p_dismoney: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,// 折后金额
                        p_doctor: this.state.thisDoctorInfo.department.name + '-' + this.state.thisDoctorInfo.name,//  接诊医生
                        p_paystate: 2,//  单个服务支付状态
                        p_servedNumber: 0,//已服务次数
                        p_isReturn: 0,//标志是否退费  0：未退费  1：已退费
                    }]),//收费明细
                },
                success: res => {
                    console.log(res);
                    console.log(this.state.patientInfo._id);
                    browserHistory.push({ pathname: 'payConfirm', state: JSON.stringify({ name: thisUserInfo.username, patientId: thisUserInfo._id, myId: res.docs._id }) });
                },
                error: err => {
                    console.log(err);
                }
            });
            return;
        }
        this.props.form.validateFields((err, fieldsValue) => {
            console.log(err, fieldsValue);
            if (!err) {
                const values = {
                    ...fieldsValue,
                    'birthday': fieldsValue['birthday'].format('YYYY-MM-DD'),
                };
                // console.log(values);
                let familyData = [];
                familyData.push({ name: values.name1, relationship: values.relationship1, gender: values.gender1, birthday: values.birthday1 ? values.birthday1.format('YYYY-MM-DD') : undefined, phone: values.phone1 })
                values.keys.map(i => {
                    let v1 = 'name1' + i;
                    let v2 = 'relationship1' + i;
                    let v3 = 'gender1' + i;
                    let v4 = 'birthday1' + i;
                    let v5 = 'phone1' + i;
                    values[v1] = fieldsValue[v1];
                    values[v2] = fieldsValue[v2];
                    values[v3] = fieldsValue[v3];
                    values[v4] = fieldsValue[v4] ? fieldsValue[v4].format('YYYY-MM-DD') : undefined;
                    values[v5] = fieldsValue[v5];
                    familyData.push({ name: values[v1], relationship: values[v2], gender: values[v3], birthday: values[v4], phone: values[v5] })
                })
                console.log(familyData);
                let url = allRouter.patientOrigin + '/patient/save';
                let that = this;
                $.ajax({
                    url: url,
                    type: "post",
                    async: true,
                    traditional: true,
                    headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                    data: {
                        username: values.name,//患者姓名
                        usersex: values.gender,//性别
                        userbirthday: values.birthday,//出生日期
                        userphone: values.phone,//手机号
                        userpapers: values.cardType,//证件类型
                        userIDcard: values.card,//证件号
                        userprovince: values.address ? values.address.join('/') : undefined,//家庭省市区地址
                        useraddress: values.addressDetail,//详细住址
                        userimg: values.Filedata ? values.Filedata[0].response ? values.Filedata[0].response.name : values.Filedata[0].name : '',//患者照片
                        membercardno: values.patientCardId,//患者卡号
                        usersource: values.patientOrigin,//用户来源
                        membertypes: values.userType,//会员类型
                        usermarriage: values.marryState,//婚姻状况
                        userproffession: values.job,//职业
                        userworkunit: values.jobAddress,//工作单位
                        usernation: values.nation,//民族
                        useremail: values.email,//邮件地址
                        familydata: JSON.stringify(familyData),//家庭信息
                        registrationmes: JSON.stringify([{ receptiontime: '', receptiontype: 0, section: { id: '', name: '' }, registerpeople: { id: JSON.parse(sessionStorage.getItem('UserInfo')).id, name: JSON.parse(sessionStorage.getItem('UserInfo')).name }, doctor: { id: '', name: '' }, registrationlv: '', registrationmoney: 0, paystate: 0 }]),//包含所有挂号信息
                        signmes: JSON.stringify([{ height: 0, weight: 0, pulse: 0, breathe: 0, bloodpressure: 0 }]),//体征信息
                    },
                    success: data => {
                        console.log(data);
                        if (data.code === 200) {
                            if (mes) {
                                message.info('患者信息增加成功');
                                this.changeTab(2);
                            } else {
                                that.setState({
                                    patientInfo: data.data,
                                }, () => {
                                    console.log('此为添加分诊信息，生成订单');
                                    console.log(this.state.patientInfo);
                                    console.log(this.state.patientInfo._id);
                                    //会员等级
                                    let discount = 1;
                                   
                                        this.setState({
                                            shouldPayed: this.state.thisDoctorInfo.price
                                        });
                                        let url = allRouter.patientOrigin + '/order/save';
                                        $.ajax({
                                            url: url,
                                            type: "post",
                                            async: true,
                                            traditional: true,
                                            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                                            data: {
                                                clinicname: this.state.storeInfo._id,//门店
                                                department: this.state.thisDoctorInfo.department.id, //科室
                                                doctor: this.state.thisDoctorInfo.id,//医生
                                                consumptiontime: getFormatDate(new Date()) + ' ' + this.state.timePhaseValue.slice(6, 11),//  就诊时间
                                                consumptionmoney: this.state.thisDoctorInfo.price,//应收金额
                                                payer: this.state.patientInfo._id,//付款人
                                                paytype: 1,//支付类型
                                                ordertype: '挂号费-' + this.state.thisDoctorInfo.department.name + this.state.thisDoctorInfo.level,//订单类型
                                                chargeschedule: JSON.stringify([{
                                                    p_name: '挂号费',//收费名称
                                                    p_Number: 1,//数量
                                                    p_price: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,//   单价
                                                    p_speci: '次',// 规格
                                                    p_money: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,//  金额
                                                    p_discount: 1,// 折扣
                                                    p_dismoney: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,// 折后金额
                                                    p_doctor: this.state.thisDoctorInfo.department.name + '-' + this.state.thisDoctorInfo.name,//  接诊医生
                                                    p_paystate: 2,//  单个服务支付状态
                                                    p_servedNumber: 0,//已服务次数
                                                    p_isReturn: 0,//标志是否退费  0：未退费  1：已退费
                                                }]),//收费明细
                                            },
                                            success: res => {
                                                console.log(res);
                                                console.log(this.state.patientInfo._id);
                                                console.log(res.docs._id)
                                                browserHistory.push({ pathname: 'payConfirm', state: JSON.stringify({ name: this.state.patientInfo.username, patientId: this.state.patientInfo._id, myId: res.docs._id }) });
                                            },
                                            error: err => {
                                                console.log(err);
                                            }
                                        })
                                        // 此为添加分诊信息，生成订单

                                })
                            }
                        } else {
                            message.info('患者信息增加失败');
                        }
                    },
                    error: err => {
                        console.log(err);
                    }
                });
            }
        })
    }
    render(){
        return (
            <div className='container triage'>
                <div className='btnBox'>
                    <Button type={this.state.tabKey === 1 ? 'primary':''} onClick={() => this.changeTab(1)}>待分诊</Button>
                    <Button style={{marginLeft:'10px'}} type={this.state.tabKey === 2 ? 'primary':''} onClick={() => this.changeTab(2)}>已分诊</Button>
                    <div className='role-manage-box-search my-clear-fix employee-manage-box-search'>
                        <div className='addetd-z employee-manage-search'>
                            <InputGroup >
                                <RangePicker style={{width:'600px'}}
                                             placeholder={['请选择日期', '请选择日期']}
                                             onChange={this.changeDate.bind(this)}
                                             format='YYYY-MM-DD'
                                             value={this.state.date}
                                />
                                <Input
                                    placeholder="请输入患者姓名或手机号"
                                    value={this.state.Inkey}
                                    onChange={(e) => this.changeInkey(e)}
                                    onPressEnter={(e)=>this.searchRoles(e)}
                                />
                            </InputGroup>
                        </div>
                        <div className="role-manage-right">
                            <Button type="primary" className='member-button' icon="search" onClick={this.searchRoles.bind(this)} >搜索</Button>
                        </div>
                    </div>
                </div>
                {
                    <div className='addpatient'>
                        <div style={{ background: '#ECECEC', padding: '30px' }}>
                            <Row gutter={16}>
                                {this.state.patientInfos.data.length?this.state.patientInfos.data.map(item=>{
                                    return <Col span={8} key={item._id} style={{marginBottom:'20px'}}>
                                        <Card bordered={false}>
                                            <img src={require('../../../images/patientDefault.png')} className="default-img"/>
                                            <div className="fsecd">
                                                <h6><b style={{fontSize:'20px',color:'#1890ff'}}>{item.username}</b>( {item.usersex+' '+(new Date().getFullYear()-item.userbirthday.slice(0,4))+'岁'} )</h6>
                                                <p>接诊类型：{item.Receptionmes?item.Receptionmes.receptiontype===0?'初诊':'复诊':''}</p>
                                                <p>登记科室：{item.registrationmes?item.registrationmes.department.department_name:''}</p>
                                                <p>接诊医生：{item.registrationmes?item.registrationmes.doctor.doctor_name:''}</p>
                                                <p>登记人员：{item.Receptionmes?item.Receptionmes.name:''}</p>
                                                <p>会员等级：{this.state.userTypeManageList.map(key=>{
                                                    if(key._id===item.membertypes){
                                                        return key.name;
                                                    }
                                                })}</p>
                                                <p>登记时间：{item.createtime}</p>
                                            </div>
                                            <span  className='triageType' size="small" style={{background:item.registrationmes?"#aaa":"#555"}}>{item.registrationmes?"待接诊":"待分诊"}</span>
                                        </Card>
                                        <div className="hdsf">
                                            <Button type="primary" onClick={()=>{browserHistory.push('patientInfoDetails/'+item._id)}}>完善资料</Button>
                                            <Button type="primary" onClick={this.handleScheduleOrAppointment.bind(this,item.status,item._id)}>{item.status===1?"安排分诊":'重新预约'}</Button>
                                        </div>
                                    </Col>}):''}
                            </Row>
                        </div>
                        {/*分页*/}
                        <div className="pagination">
                            <Pagination  showQuickJumper current={this.state.pageindex} total={ this.state.patientInfos.counts||1} defaultPageSize={this.state.pagesize} onChange={this.changePage.bind(this)} />
                        </div>
                    </div>
                }
                {/*选择医生模态框*/}
                <Modal
                    title="选择医生"
                    className="large-model"
                    visible={this.state.visible}
                    onCancel={
                        () => {
                            this.setState({ visible: false });
                            this.setState({
                                isHavingId: false,
                            })
                        }}
                    footer={null}
                >
                    <div className='xzys'>
                        <Select style={{ width: 150 }} placeholder="请选择时间段" onChange={this.handleChangeTimePhase.bind(this)} value={this.state.timePhaseValue}>
                            {this.state.allTimePhase.length ? this.state.allTimePhase.map((item, index) =>
                                <Option value={item} key={index}>{item}</Option>
                            ) :
                                ""}
                        </Select>
                        <Select style={{ width: 150 }} placeholder="请选择科室" onChange={this.handleChangeDepartment.bind(this)} value={this.state.departmentValue}>
                            <Option value='' >请选择</Option>
                            {this.state.departmentsList.map(item => {
                                return <Option value={item._id} key={item._id}>{item.name}</Option>
                            })}
                        </Select>
                        <Select style={{ width: 150 }} placeholder="请选择医生" onChange={this.handleChangeDoctor.bind(this)} value={this.state.doctorValue}>
                            <Option value='' >请选择</Option>
                            {this.state.everyDoctorList.length ? this.state.everyDoctorList.map((item, index) => {
                                return <Option value={item._id} key={index}>{item.name}</Option>
                            }) : ''}
                        </Select>
                    </div>
                    <div className="xzys1">
                        {this.state.registrationFeeList.map(item => {
                            return (<a href="javascript:void(0);" key={item._id} onClick={this.medicalInformation.bind(this, item)}>
                                <Col span={3}>
                                    <Card bordered={false}>
                                        <img src={require('../../../images/doctorDeafult.png')} className="default-img" />
                                        <div className="fsecd">
                                            <h6 style={{ marginBottom: '0px' }}>{item.name}</h6>
                                            <h6>({item.department ? item.department.name : ''})</h6>
                                            <p>待接诊：{item.totreat?item.totreat:0}人</p>
                                            <p>已接诊：{item.alreadyaccepts?item.alreadyaccepts:0}人</p>
                                        </div>
                                    </Card>
                                </Col>
                            </a>)
                        })}
                    </div>
                </Modal>
                {/*点击医生头像显示医生挂号费详细信息*/}
                <Modal title="就诊信息确认" visible={this.state.visible1} className="medicalInformation"
                       onCancel={() => {
                           this.setState({ visible1: false });
                       }}
                       onOk={this.handleTriageConfirm.bind(this, this.state.isHavingId)}
                >
                    <p>就诊科室：{this.state.thisDoctorInfo.department ? this.state.thisDoctorInfo.department.name : ''}</p>
                    <p>就诊医生：{this.state.thisDoctorInfo.name} {this.state.thisDoctorInfo.level}</p>
                    <p>就诊时间：{new Date().toLocaleDateString()} {this.state.timePhaseValue.slice(6, 11)}</p>
                    <p><b>挂号费：￥{this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price:0}</b></p>
                </Modal>
            </div>
        );
    }
}
export default Triage;